package servlet;

import java.io.IOException;


import java.text.DateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.BookService;
import service.BorrowService;
import service.ReaderSerivice;
import vo.BookBean;

public class BookBorrowAdd extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		int rid=Integer.parseInt(req.getParameter("rid"));
		int bid=Integer.parseInt(req.getParameter("bid"));
		String outtime=req.getParameter("outtime");
		String day=req.getParameter("day");
		int maxday=30;
		if(outtime==null){
		Date time=new Date();
		outtime=DateFormat.getDateInstance().format(time);
		}
		if(day!=""){
			maxday=Integer.parseInt(day);
		}
		BorrowService bws=new BorrowService();
		bws.insert(bid, rid, outtime, maxday);
		BookService bs=new BookService();
		 List<Object> list = bs.get(bid);
		 BookBean bb=(BookBean) list.get(0);
		 Double mn=bb.getB_price();
		 ReaderSerivice rs=new ReaderSerivice();
		 rs.dprice(rid, mn);
		req.getRequestDispatcher("/jsp/bookBorrow.jsp").forward(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
}
